<?php
// +----------------------------------------------------------------------
// | Longbing [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright Chengdu longbing Technology Co., Ltd.
// +----------------------------------------------------------------------
// | Website http://longbing.org/
// +----------------------------------------------------------------------
// | Sales manager: +86-13558882532 / +86-13330887474
// | Technical support: +86-15680635005
// | After-sale service: +86-17361005938
// +----------------------------------------------------------------------

namespace app\shortvideo\model;

use app\BaseModel;
use think\facade\Db;

class ShortvideoCompany extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_shortvideo_company';

    /**
     * @param $dis
     * @param $data
     * @return int
     * 编辑
     */
    public function companyVideoAdd($data){
        $data['create_time'] = time();
        $data['update_time'] = time();
        $data['status']      = 1;
        $res = $this->insert($data);
        return $res;
    }

    /**
     **@param $dis
     * @功能说明:
     * @author lichuanming
     * @DataTime: 2020/5/18 17:25
     */
    public function getCompanyIds($dis){
        $data = AdminCompany::where($dis)->column('id');
        $company_id = [];
        if(!empty($data)){
            foreach ($data as $v){
                $company_id[] = $this->reset($v);
            }
        }
        return array_values($company_id);
    }

    /**
     **@param $dis
     * @功能说明:
     * @author lichuanming
     * @DataTime: 2020/5/18 17:26
     */
    public function getId($dis){
        $data = $this
            ->alias('a')
            ->leftJoin('longbing_card_company b','a.company_id=b.id')
            ->where($dis)
            ->column('company_id');
        $company_id = [];
        if(!empty($data)){
            foreach ($data as $v){
                $company_id[] = $this->reset($v);
            }
        }
        return array_values($company_id);
    }


    /**
     * @author chenniang
     * @DataTime: 2021-08-17 11:01
     * @功能说明:获取员工id
     */
    public function getStaffId($video_id){

        $dis = [

            'a.video_id' => $video_id,

            'b.is_staff' => 1
        ];

        $data = $this->alias('a')
                ->join('longbing_card_user_info b','a.staff_id = b.fans_id')
                ->where($dis)
                ->column('fans_id');

        return array_values($data);


    }

    /**
     * @param $where
     * @param $data
     * @return int
     * 删除
     */
    public function companyVideoDel($where,$data){
        $res = $this->where($where)->where('id','not in',$data)->delete();
        return $res;
    }

    /**
     * @param $where
     * @return int
     * 查询
     */
    public function companyVideoFind($where){
        $data = $this->where($where)->find();
        return $data;
    }

    /**
     * User: chenniang
     * Date: 2019-09-25 15:29
     * @return void
     * descption:转换插入数据
     */
    public function changeData($ids){
        $data = [];
        if(is_array($ids)){

            foreach ($ids as $k =>$v){
                $data[] = array_pop($v);
            }
        }
        return $data;
    }

    /**
     * @param $id
     * 回显
     */
    public function reset($id,&$data=array()){
        $cate   = AdminCompany::where(['id'=>$id])->find();
        if(!empty($cate)&&$cate['pid']!=$cate['id']){
            array_unshift($data,$cate['id']);
            $this->reset($cate['pid'],$data);
        }
        return $data;
    }

}